package TankGame04;

import java.util.Vector;

public class EnemyTank extends Tank implements Runnable {
    @Override
    public void run() {
        while (true) {
            //坦克根据方向来继续移动
            switch (getDirect()) {
                case 0:
                    for (int i = 0; i < 5; i++) {
                        if (getY() > 0)
                            moveUp();
                        if (getY() == 0){
                            break;
                        }
//                        else if (getY() == 0) {
//                            moveDown();
//                            setDirect(2);
//                        }
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                case 1:
                    for (int i = 0; i < 5; i++) {
                        if (getX() + 60 < 1000)
                            moveRight();
                        if (getX() + 60 == 1000){
                            break;
                        }
//                        else if (getX() == 940) {
//                            moveLeft();
//                            setDirect(3);
//                        }
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                case 2:
                    for (int i = 0; i < 5; i++) {
                        if (getY() + 60 < 750)
                            moveDown();
                        if (getY() + 60 == 750){
                            break;
                        }
//                        else if (getY() == 690) {
//                            moveUp();
//                            setDirect(0);
//                        }
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                case 3:
                    for (int i = 0; i < 30; i++) {
                        if (getX() > 0)
                            moveLeft();
                        if (getX()  == 0){
                            break;
                        }
//                        else if (getX() == 0) {
//                            moveRight();
//                            setDirect(1);
//                        }
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
            }

            //让坦克随机移动
            //生成0-3的一个随机数
            int random = (int) (Math.random() * 4);
            //让每个坦克对象随机改变一个方向，下次进入循环的时候
            setDirect(random);
            if (isLive == false) {
                break;
            }
        }
    }

    Vector<Bullet> bulletVector = new Vector<>();
    private boolean isLive = true;

    public EnemyTank(int x, int y) {
        super(x, y);
    }

    public Vector<Bullet> getBulletVector() {
        return bulletVector;
    }

    public void setBulletVector(Vector<Bullet> bulletVector) {
        this.bulletVector = bulletVector;
    }

    public boolean getIsLive() {
        return isLive;
    }

    public void setIsLive(boolean live) {
        isLive = live;
    }
}
